<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>

        // 面向对象的特征：封装、继承、多态
        // 封装不需要把内部的细节信息展示给别人
        class Computer {
            constructor(type, price) {
                this.type = type;
                //私有属性 习惯在变量名前面加上下划线
                // 对于外部而言，私有属性不可访问，但对于内部而言，可以访问私有属性
                const _price = price;
            }

            show() {
                console.log(this.price);
            }
        }

        let lenovo = new Computer('lenovo', 5000);
        console.log(lenovo.type);
        console.log(lenovo.price);
        console.log(lenovo._price);

        //继承
        //子类会继承父类身上的属性和方法

        class Person {
            constructor(gender, age, name, salary) {
                this.gender = gender;
                this.age = age;
                this.name = name;
                this.salary = salary
            }
            introduce() {
                console.log(`我叫${this.name},我今年${this.age}`);
            }
        }

        class Student extends Person {
            constructor(gender, age, name, id, salary) {
                super(gender, age, name, salary);
                this.id = id;
            }

            introduce() {
                console.log(`我叫${this.name},我今年${this.age},哈哈哈哈`);
            }
            study(){
                console.log('study～～～～');
            }

        }


        let p = new Person('男', 28, 'zhangsan', 3000);
        console.log(p);
        p.introduce()

        let stu = new Student('女', 12, '小花', '202300101', 1500);
        console.log(stu);
        //多态
        stu.introduce()
        stu.study()



    </script>

</body>

</html>